package com.taa.domain.trade.service.discount.impl;

import com.taa.domain.trade.service.discount.IDiscountStrategy;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @Author: taa
 * @Desc: 满减策略
 * @Create: 2025-06-01 19:19
 **/
@Component("MJ")
public class MJDiscountStrategy implements IDiscountStrategy {

    @Override
    public String getStrategyType() {
        return "MJ";
    }

    @Override
    public BigDecimal calculate(BigDecimal originalPrice, String strategyValue) {
        String[] parts = strategyValue.split(",");
        BigDecimal fullAmount = new BigDecimal(parts[0]);
        BigDecimal reduction = new BigDecimal(parts[1]);
        return originalPrice.compareTo(fullAmount) >= 0 ?
                originalPrice.subtract(reduction) : originalPrice;
    }
}
